from django.db import models

# Create your models here.

class DbComponent(models.Model):
    system_name = models.CharField(max_length=100, blank=True)
    system_number = models.CharField(max_length=100, blank=True)
    unique_id = models.CharField(max_length=100, blank=True)
    item_name = models.CharField(max_length=150, blank=True)
    building_number = models.CharField(max_length=100, blank=True)
    location = models.CharField(max_length=150, blank=True)
    is_critical = models.CharField(max_length=100, blank=True)
    additional_identifiers = models.CharField(max_length=254, blank=True)

    def __unicode__(self):
        return self.unique_id

class DbPicture(models.Model):
    component = models.ForeignKey(DbComponent)
    root_directory = models.CharField(max_length=150)
    file_name = models.CharField(max_length=150)
    file_extension = models.CharField(max_length=10)

    def __unicode__(self):
        return self.file_name

class DbMechanical(models.Model):
    component = models.OneToOneField(DbComponent)
    manufacturer = models.CharField(max_length=100, blank=True)
    model_number = models.CharField(max_length=100, blank=True)
    serial_number = models.CharField(max_length=100, blank=True)
    size = models.CharField(max_length=100, blank=True)
    flowrates = models.CharField(max_length=100, blank=True)
    rpm = models.CharField(max_length=100, blank=True)
    material = models.CharField(max_length=100, blank=True)
    
    def __unicode__(self):
        return self.manufacturer + ': ' + self.model_number

class DbElectrical(models.Model):
    component = models.OneToOneField(DbComponent)
    manufacturer = models.CharField(max_length=100, blank=True)
    model_number = models.CharField(max_length=100, blank=True)
    serial_number = models.CharField(max_length=100, blank=True)
    rpm = models.CharField(max_length=100, blank=True)
    horse_power = models.CharField(max_length=100, blank=True)
    volts = models.CharField(max_length=100, blank=True)
    hertz = models.CharField(max_length=100, blank=True)
    phase = models.CharField(max_length=100, blank=True)
    amps = models.CharField(max_length=100, blank=True)
    
    def __unicode__(self):
        return self.manufacturer + ': ' + self.model_number

class DbIandC(models.Model):
    component = models.OneToOneField(DbComponent)
    manufacturer = models.CharField(max_length=100, blank=True)
    model_number = models.CharField(max_length=100, blank=True)
    serial_number = models.CharField(max_length=100, blank=True)
    output_range = models.CharField(max_length=100, blank=True)
    display_range = models.CharField(max_length=100, blank=True)
    medium = models.CharField(max_length=100, blank=True)
    analog_or_digital = models.CharField(max_length=100, blank=True)
    
    def __unicode__(self):
        return self.manufacturer + ': ' + self.model_number

class DbFlow(models.Model):
    component = models.ForeignKey(DbComponent)
    sub_type = models.CharField(max_length=50) # i.e. mechanical, electrical...
    to_or_from = models.CharField(max_length=10)
    what = models.CharField(max_length=300)

    def __unicode__(self):
        return self.sub_type + ' ' + self.to_or_from.lower() \
                + ': ' + self.what.strip()

class DbDrawing(models.Model):
    component = models.ForeignKey(DbComponent)
    drawing_number = models.CharField(max_length=100)

    def __unicode__(self):
        return self.drawing_number

